home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / DArray2 < prev    next >
Text File  |  1994-07-27  |  2KB  |  123 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "DeskLib:WimpSWIs.h"
  5.  
  6. #include "Shell.Array.h"
  7. #include "Shell.Extra.h"
  8. #include "Shell.SafeAlloc.h"
  9.  
  10.  
  11. #define COLUMN_WIDTH 10
  12.  
  13.  
  14. typedef struct    {
  15.     double        **data;
  16.     wimp_point    size;
  17.     }
  18.     Shell_2DDoubleArrayInfo;
  19.  
  20.  
  21.  
  22.  
  23.  
  24. static void    Shell_2DDoubleArrayRedrawer(
  25.     Shell_convertpoint    convert,
  26.     wimp_point        rectsize,
  27.     void            *reference,
  28.     const wimp_rect        *redrawrect
  29.     )
  30. {
  31.     wimp_rect        rect    = *redrawrect;
  32.     Shell_2DDoubleArrayInfo    *info    = (Shell_2DDoubleArrayInfo *) reference;
  33.     int            i, j;
  34.     char            s[64];
  35.  
  36. Shell_ConvertToSubTextRect2( &rect, rectsize);
  37. rect.min.x /= COLUMN_WIDTH;
  38. rect.max.x /= COLUMN_WIDTH;
  39.  
  40.  
  41. for ( i=rect.min.x; i<=rect.max.x; i++)    {
  42.     int x = i*COLUMN_WIDTH*Shell_TEXTXSIZE;
  43.  
  44.     for ( j=rect.min.y; j<=rect.max.y; j++)    {
  45.  
  46.         sprintf( s, "%.2g", info->data[j][i]);
  47.             /* Note the order. This is so that matrices are displayed with first    */
  48.             /* indice denoting the row, and the second denoting the column.        */
  49.         s[ COLUMN_WIDTH-1] = '\0';
  50.  
  51.         Shell_PrintString( s, x, rectsize.y - j*Shell_TEXTYSIZE, convert);
  52.  
  53.         }
  54.     }
  55.  
  56. return;
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. static BOOL Shell_2DDoubleArraySaver( char *filename, Shell_rectblock *r)
  64. {
  65. FILE    *f;
  66. Shell_2DDoubleArrayInfo    *info    = (Shell_2DDoubleArrayInfo *) r->reference;
  67. int            x, y;
  68.  
  69. f = fopen( filename, "w");
  70. if (!f)    return FALSE;
  71.  
  72. for ( y=0; y<info->size.y; y++)    {
  73.     for ( x=0; x<info->size.x; x++)    {
  74.         fprintf( f, "%.2g", info->data[y][x]);
  75.         fprintf( f, "\t");
  76.         }
  77.     fprintf( f, "\n");
  78.     }
  79.  
  80. fclose( f);
  81.  
  82. return TRUE;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. Shell_rectblock    *Shell_Add2DDoubleArray(
  90.     Shell_windblock *windblock,
  91.     int x, int y,
  92.     int xsize, int ysize,
  93.     int forecol, int backcol,
  94.     double **data
  95.     )
  96.  
  97. {    Shell_rectblock        *r;
  98.     Shell_2DDoubleArrayInfo    *info =
  99.         Shell_SafeMalloc( sizeof( Shell_2DDoubleArrayInfo));
  100.  
  101.  
  102. info->data    = data;
  103. info->size.x    = xsize;
  104. info->size.y    = ysize;
  105.  
  106. r = Shell_AddRectangle2(
  107.     windblock,
  108.     x, y - ysize*Shell_TEXTYSIZE,
  109.     x + xsize * COLUMN_WIDTH * Shell_TEXTXSIZE, y,
  110.     Shell_2DDoubleArrayRedrawer,
  111.     (void *) info
  112.     );
  113.  
  114. r->saver    = Shell_2DDoubleArraySaver;
  115. r->size        = COLUMN_WIDTH * xsize * ysize;
  116.  
  117. Shell_MakeRectIcon( r, forecol, backcol, "r1");
  118.  
  119. return r;
  120. }
  121.  
  122.  
  123.